/**
 * moieo.net
 * @author Moieo
 */
package cn.moieo.carcontrol

import android.app.Application
import android.util.Log
import cn.wch.uartlib.WCHUARTManager
import java.util.Locale

fun Int.toHexString(minLength: Int = 1): String {
    var hexString = Integer.toHexString(this).uppercase(Locale.getDefault())
    while (hexString.length < minLength) {
        hexString = "0$hexString"
    }
    return hexString
}

class MxApplication : Application() {
    private fun println(msg: String) {
        Log.i(javaClass.simpleName, msg)
    }

    override fun onCreate() {
        super.onCreate()
        // 初始化沁恒WCH串口驱动
        val wch = WCHUARTManager.getInstance()
        wch.init(this)
        wch.enumDevice().forEach {
            println("==================================")
            println("productName: ${it.productName}")
            println("deviceName: ${it.deviceName}")
            println("productId: 0x${it.productId.toHexString()}")
            println("vendorId: 0x${it.vendorId.toHexString()}")
            println("==================================")
        }
    }
}